package com.work.example.demo5.controller;

import com.work.example.demo5.domain.BooksEntity;
import com.work.example.demo5.domain.formEntity;
import com.work.example.demo5.domain.vo.BookEntityVo;
import com.work.example.demo5.service.BookService;
import com.work.example.demo5.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
@CrossOrigin
public class BookController {
    @Autowired
    private BookService bookService;
    @PostMapping("/getbooks")
    public R getBooks(@RequestBody formEntity formEntity) {
        return R.success(bookService.queryByForm(formEntity));
    }

    @GetMapping("/list")
    public R list() {
        return R.success(bookService.getAllList());
    }

    @GetMapping("/deletebook")
    public R deletebook(@RequestParam("id") Long bookId) {
        System.out.println(bookId);
        bookService.removebook(bookId);
        return R.ok();
    }
    @PostMapping("/addbook")
    public R addbook(@RequestBody BooksEntity booksEntity) {
        System.out.println(booksEntity);
        bookService.savebook(booksEntity);
        return R.ok();
    }

    @PostMapping("/updatebook")
    public R updatebook(@RequestBody BookEntityVo bookEntityVo) {
        System.out.println(bookEntityVo);
        bookService.updatebook(bookEntityVo);
        return R.ok();
    }

}
